package net.alpenviewer.map;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public abstract class ColorEncoder {

	/**
	 * @param val
	 * @return sRGB (TYPE_INT_ARGB)
	 */
	public abstract int getEncodedColor(double val);
	
	public abstract BufferedImage getVerticalLegend(int width, int height, Object ... parameters);
	
	public static BufferedImage resize(BufferedImage img, int newWidth, int newHeight) {
		int width = img.getWidth();
		int height = img.getHeight();
		BufferedImage dimg = new BufferedImage(newWidth, newHeight, img.getType());
		Graphics2D g = dimg.createGraphics();
		g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		g.drawImage(img, 0, 0, newWidth, newHeight, 0, 0, width, height, null);
		g.dispose();
		return dimg;
	}
}
